
#include <Type\Province.h>

#include "..\Data\User.h"

#include "PersonalInfo.h"


namespace TC
{
    namespace Request
    {
        void TC::Request::PersonalInfo::query()
        {
            if (status() == Status::Communicating)
                return;
            AbstractRemoteProcedure::get("user/queryPersonalInfo",
            {
                { "signature", Data::User::instance()->signature() },
            });
        }

        void TC::Request::PersonalInfo::onDataReady(QDataStream &stream)
        {
            bool result;
            stream >> result;
            if (result)
            {
                QString email, phone;

                TCServer::Type::Province province;
                QString city;

                QString name, head;
                uint level;
                bool sex;

                stream >> email >> phone;
                stream >> province >> city;
                stream >> name >> head >> level >> sex;

                Data::User::instance()->setEmail(email);
                Data::User::instance()->setPhone(phone);

                Data::User::instance()->setProvince(TCServer::Type::provinceToString(province));
                Data::User::instance()->setCity(city);

                Data::User::instance()->setName(name);
                Data::User::instance()->setHead(head);
                Data::User::instance()->setLevel(level);
                Data::User::instance()->setSex(sex);

                setOk();
            }
            else
                setFailed();
        }

    }
}